package com.tanhua.server.controller;

import com.tanhua.commons.utils.UserHolder;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.server.service.UserInfoService;
import com.tanhua.server.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;
    //保存用户信息

    @Autowired
    private Userservice userservice;

    @PostMapping("/loginReginfo")
    // 首次登录---完善资料
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo){
        //设置id

        userInfo.setId(Long.valueOf(UserHolder.getUserId()));
        //调用service
        userInfoService.save(userInfo);
    return ResponseEntity.ok().body(null);
    }

    @PostMapping("/loginReginfo/head")
    public ResponseEntity head(MultipartFile headPhoto) throws IOException {

        //设置id

        //调用service
        userInfoService.updateHead(headPhoto,UserHolder.getUserId());
        return ResponseEntity.ok(null);
    }


}
